package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbBusinessTel;
import com.ruoyi.system.service.ITbBusinessTelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商家联系电话Controller
 * 
 * @author ruoyi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/system/tel")
public class TbBusinessTelController extends BaseController
{
    @Autowired
    private ITbBusinessTelService tbBusinessTelService;

    /**
     * 查询商家联系电话列表
     */
    @PreAuthorize("@ss.hasPermi('system:tel:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbBusinessTel tbBusinessTel)
    {
        startPage();
        List<TbBusinessTel> list = tbBusinessTelService.selectTbBusinessTelList(tbBusinessTel);
        return getDataTable(list);
    }

    /**
     * 导出商家联系电话列表
     */
    @PreAuthorize("@ss.hasPermi('system:tel:export')")
    @Log(title = "商家联系电话", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbBusinessTel tbBusinessTel)
    {
        List<TbBusinessTel> list = tbBusinessTelService.selectTbBusinessTelList(tbBusinessTel);
        ExcelUtil<TbBusinessTel> util = new ExcelUtil<TbBusinessTel>(TbBusinessTel.class);
        util.exportExcel(response, list, "商家联系电话数据");
    }

    /**
     * 获取商家联系电话详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbBusinessTelService.selectTbBusinessTelById(id));
    }

    /**
     * 新增商家联系电话
     */
    @PreAuthorize("@ss.hasPermi('system:tel:add')")
    @Log(title = "商家联系电话", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbBusinessTel tbBusinessTel)
    {
        return toAjax(tbBusinessTelService.insertTbBusinessTel(tbBusinessTel));
    }

    /**
     * 修改商家联系电话
     */
    @PreAuthorize("@ss.hasPermi('system:tel:edit')")
    @Log(title = "商家联系电话", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbBusinessTel tbBusinessTel)
    {
        return toAjax(tbBusinessTelService.updateTbBusinessTel(tbBusinessTel));
    }

    /**
     * 删除商家联系电话
     */
    @PreAuthorize("@ss.hasPermi('system:tel:remove')")
    @Log(title = "商家联系电话", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbBusinessTelService.deleteTbBusinessTelByIds(ids));
    }
}
